
export default {

//日期数据处理
    dateFrm(type) {
      if (type === "date" || type === "daterange") {
        return "yyyy-MM-dd";
      } else if (type == "datetime" || type === "datetimerange") {
        return "yyyy-MM-dd HH:mm:ss";
      } else if(type == 'month'){
      	return "yyyy-MM";
      }else {
        return "";
      }
    },
    todayFun(data,pre){//传值得到时间2020-05-20
    	if(!data){
    		data = new Date();
    	}
    	
		var y = data.getFullYear()
		
		var m;
		if(pre){
			m = data.getMonth() 
		}else{
			m = data.getMonth() + 1
		}
		m = m < 10 ? '0' + m : m
		var d = data.getDate()
		d = d < 10 ? ('0' + d) : d
		let today = y + '-' + m + '-' + d
        return today
    },
    getNowTime(time) {//年月日时分秒
    	if(!time){
    		time = new Date();
    	}
		var year = time.getFullYear();
		var m = time.getMonth() + 1;
		m = m < 10 ? '0' + m : m
		var d = time.getDate();
		d = d < 10 ? ('0' + d) : d
		var hour = time.getHours() < 10 ? "0" + time.getHours() : time.getHours();
		var minute = time.getMinutes() < 10 ? "0" + time.getMinutes() : time.getMinutes();
		var second = time.getSeconds() < 10 ? "0" + time.getSeconds() : time.getSeconds();
		var milliSeconds = time.getMilliseconds();
		var currentTime = year+'-'+m + '-' + d + ' ' + hour + ':' + minute + ':' + second;
		return currentTime;
	},
	mGetDate(_year,_month){//得到一个月的天数
		if(!_year && !_month){
    		_year = new Date().getFullYear();
    		_month = new Date().getMonth()+1
    	}
	     var year = _year;
	     var month = _month;
	     var d = new Date(year, month, 0);
	     return d.getDate();
	},
	getMonthDays(date) {
		var year = date.split('-')[0]
		var month = parseInt(date.split('-')[1])
		var d = new Date(year, month, 0);
	  return d.getDate();
	},
	getCurrentMonth() { // 获取当前月份
		var date = new Date();
		let month = date.getMonth() + 1
		let result = date.getFullYear() + '-' + (month<10?('0' + month) : month)
		return result
	},
	getCurrentDate() { // 获取当前日期
		var date = new Date();
		let month = date.getMonth() + 1
		var d = date.getDate();
		d = d < 10 ? ('0' + d) : d
		let result = date.getFullYear() + '-' + (month<10?('0' + month) : month) + '-' + d
		return result
	},
	addMonth(date,n) { //加减月份
		var date = new Date(date)
		date.setMonth(date.getMonth() + n)
		let month = date.getMonth() + 1
		return date.getFullYear() + '-' + (month<10?('0' + month) : month)
	},
	getMonthFirstDayWeek(month) { // 获取本月第一天是星期几
		var date=new Date(month);
		date.setDate(1);
		return date.getDay();
	},
	getNextDate(date,day) {  
		var dd = new Date(date);
		dd.setDate(dd.getDate() + day);
		var y = dd.getFullYear();
		var m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
		var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
		return y + "-" + m + "-" + d;
	},
	getMonthLastDayWeek(month) {// 获取本月最后一天是星期几
		var date=new Date(month);
		var currentMonth=date.getMonth();
		var nextMonth=++currentMonth;
		var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
		var oneDay=1000*60*60*24;
		var lastDay = new Date(nextMonthFirstDay-oneDay);
		return lastDay.getDay()
	},
	getWeek(date) {
		let arr = ['周日','周一','周二','周三','周四','周五','周六']
		var newDate = new Date(date);
		return arr[newDate.getDay()]
	}
}